#include <stdio.h>
#include <iostream>
#include "encodedict.h"
#include "decodedict.h"

#define MODE_ENCODE_DICT					1
#define MODE_DECODE_DICT  					2
#define MODE_DECODE_PASSWORD  		3

int parseInput(void)
{
	int mode;
	int max_error = 3;

MODE_INPUT:
	std::cout <<"请选择你操作类型(1、2、3)："<<std::endl;
	std::cout <<"1：生成口令字典."<<std::endl;
	std::cout <<"2：输入加密后密文，使用口令字典解码，显示明文."<<std::endl;
	std::cout <<"3：使用口令字典生成密码"<<std::endl;
	std::cout <<"请输入你的操作类型：";
	scanf("%d", &mode);

	if (mode == MODE_ENCODE_DICT || mode == MODE_DECODE_DICT ||  mode == MODE_DECODE_PASSWORD) {
		return mode;
	}

	max_error -= 1;
	if (max_error > 0) {
		goto MODE_INPUT;
	} else {
		std::cout <<"错误输入超过3次，即将退出！"<<std::endl;
	}

	return mode;
}

void run(int mode)
{
	if (mode == MODE_ENCODE_DICT)
		encondeDict();
	else if  (mode == MODE_DECODE_DICT)
		decondeDict();
	else
		generatePassword();
}

int main(int argc, char *argv[])
{
	int mode = 0;
	std::cout <<"==================================================================="<<std::endl;
	mode = parseInput();
	run(mode);
    std::cout <<"==================================================================="<<std::endl;
	return 0;
}

